<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<body>
	<ui:composition template="/pages/protected/user/default.xhtml">
		<ui:define name="content">
			<h4>
				<h:outputLabel value="#{msgs.invalidID}"
					rendered="#{transactionMB.invalidUserID}" />
			</h4>
			<h:panelGroup rendered="#{!transactionMB.invalidUserID}">

				<h:form id="transactionsList">

					<h:link outcome="createTransaction"
						value="#{msgs.createTransaction}"
						rendered="#{userMB.thisRequestForMe}" />

					<h:link
						outcome="transactionStatistics?userid=#{userMB.currentRequestUser.id}"
						value="#{msgs.viewStatistics}" />

					<p:dataTable id="mylist" value="#{transactionMB.allTransactions}"
						var="transaction" styleClass="table"
						headerClass="tableColumnsHeader"
						rowStyleClass="#{transaction.typeString}">
						<p:column>
							<f:facet name="header">
								#{msgs.date}
							</f:facet>
						#{transaction.formattedDate}
					</p:column>
						<p:column>
							<f:facet name="header">
								#{msgs.amount}
							</f:facet>
						#{transaction.amount} HUF
					</p:column>
						<p:column>
							<f:facet name="header">
								#{msgs.type}
						</f:facet>
						#{msgs[transaction.typeString]}
					</p:column>
						<p:column>
							<f:facet name="header">
								#{msgs.category}
						</f:facet>
						#{transaction.category.name}
					</p:column>
					<p:column>
							<f:facet name="header">	
									#{msgs.numComments}		
							</f:facet>		
							#{commentMB.getNumberofCommentsForTransaction(transaction.id)}		
					</p:column>
					<p:column>
							<f:facet name="header">
								#{msgs.actions}
						</f:facet>
							<h:inputHidden value="#{transaction.id}" />
							<h:commandButton rendered="#{userMB.thisRequestForMe}"
								action="#{transactionMB.deleteTransaction()}"
								value="#{msgs.delete}"
								onclick="if (!confirm('#{msgs.areYouSure}')) return false">
								<f:setPropertyActionListener
									target="#{transactionMB.transaction}" value="#{transaction}" />
							</h:commandButton>
							<h:link outcome="transactionDetails" value="#{msgs.visit}"
								title="#{msgs.visit}">
								<f:param name="id" value="#{transaction.id}"></f:param>
							</h:link>
					</p:column>
					</p:dataTable>


				</h:form>
			</h:panelGroup>
		</ui:define>
	</ui:composition>
</body>
</html>